
#ifndef DISPLAYDRIVER_C
#define DISPLAYDRIVER_C

#include "displaydriver.h"


static uint8_t *displayDriverImage;
static uint8_t displayDataCount;    /* 0 - 4, index to active display data array _LED */

static uint8_t displayBank;


static void DisplayDriverShift(uint8_t data1, uint8_t data2);

void DisplayDriverClear(void);


void DisplayDriverDelay(void)
{
	//UINT8 i;
	
	//for (i = 1; i > 0; i--);

	//__nop();
	//__nop();
	//__nop();
	//__nop();
	
}

void DisplayDriverInitialize(void)
{	
    displayDriverImage = ImageAddress();
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
	//UINT8 image_byte1 = 0;
	//UINT8 image_byte2 = 0;

//1ms
void DisplayDriverProcess(void)
{
	uint8_t image_byte1 = 0;
	uint8_t image_byte2 = 0;
	
	//DISPLAY_DRIVER_DIG1 = 1;
	//DISPLAY_DRIVER_DIG2 = 1;
	DisplayDriverClear();
	
	//image_byte1 = 0xFF;
	//image_byte2 = 0xFF;
	image_byte1 = displayDriverImage[displayDataCount++];
	image_byte2 = displayDriverImage[displayDataCount++];
	
	//if(userGetEcoStatus())
	//{
	//	image_byte2=0x00;
	//}

	
	DisplayDriverShift(image_byte1, image_byte2);
//	DisplayIconShift(1, 1);
	switch (displayBank++)
	{
		case 0:
		    DISPLAY_DRIVER_DIG1 = 0;
		    break;
		case 1:
		    DISPLAY_DRIVER_DIG2 = 0;
		    displayBank = 0;
			displayDataCount = 0;
		    break;
		default:
		    break;
	}
}


static void DisplayDriverShift(uint8_t data1, uint8_t data2)
{
	if (data1 & 0x01)
	    DISPLAY_DRIVER_SEG1 = 1;
    else
	    DISPLAY_DRIVER_SEG1 = 0;
	if (data1 & 0x02)
	    DISPLAY_DRIVER_SEG2 = 1;
    else
	    DISPLAY_DRIVER_SEG2 = 0;
	if (data1 & 0x04)
	    DISPLAY_DRIVER_SEG3 = 1;
    else
	    DISPLAY_DRIVER_SEG3 = 0;
	if (data1 & 0x08)
	    DISPLAY_DRIVER_SEG4 = 1;
    else
	    DISPLAY_DRIVER_SEG4 = 0;
	if (data1 & 0x10)
	    DISPLAY_DRIVER_SEG5 = 1;
    else
	    DISPLAY_DRIVER_SEG5 = 0;
	if (data1 & 0x20)
	    DISPLAY_DRIVER_SEG6 = 1;
    else
	    DISPLAY_DRIVER_SEG6 = 0;
	if (data1 & 0x40)
	    DISPLAY_DRIVER_SEG7 = 1;
    else
	    DISPLAY_DRIVER_SEG7 = 0;
	//data2
	if (data2 & 0x01)
	    DISPLAY_DRIVER_SEG8 = 1;
    else
	    DISPLAY_DRIVER_SEG8 = 0;
	if (data2 & 0x02)
	    DISPLAY_DRIVER_SEG9 = 1;
    else
	    DISPLAY_DRIVER_SEG9 = 0;
}

void DisplayDriverClear(void)
{
	DISPLAY_DRIVER_DIG1 = 1;
	DISPLAY_DRIVER_DIG2 = 1;
	DisplayDriverShift(0, 0);
}

#endif